import { Body, Controller, Post, Req } from '@nestjs/common';
import { MemberService } from "./member.service";
import { ApiBasicAuth, ApiExtraModels, ApiOperation, ApiTags } from "@nestjs/swagger";
import { UserLoginReqVo } from 'src/vo/member/user-login-req.vo';
import { Request } from 'express';
import { ResultVo } from 'src/vo/common/result.vo';
import { GetCurrentUser } from 'src/utils/common.utils';
import { UserCodeReqVo } from 'src/vo/member/user-code-req.vo';
import { UserRegisterReqVo } from 'src/vo/member/user-register-req.vo';
import { ApiResult } from 'src/decorators/api-result.decorator';
import { MemberEntity } from './member.entity';
import {UserIdVo} from "../../vo/member/user-id.vo";
import {PayPasswordVo} from "../../vo/member/pay-password.vo";

@ApiExtraModels(MemberEntity, ResultVo)
@Controller('member')
@ApiTags('会员管理')
@ApiBasicAuth("token")
export class MemberController {
    constructor(private readonly memberService: MemberService) { }

    /**
     * 获取验证码
     * @param userLoginReqVo 
     * @returns 
     */
    @Post("getCode")
    @ApiResult()
    @ApiOperation({ summary: '获取验证码接口' })
    async redister(@Body() userCodeReqVo: UserCodeReqVo) {
        return await this.memberService.getCode(userCodeReqVo)
    }

    /**
    * 登陆
    * @param userLoginReqVo 
    * @returns 
    */
    @Post("register")
    @ApiResult()
    @ApiOperation({ summary: '用户注册接口' })
    async register(@Body() userRegisterReqVo: UserRegisterReqVo) {
        return await this.memberService.register(userRegisterReqVo)
    }

    /**
     * 登陆
     * @param userLoginReqVo 
     * @returns 
     */
    @Post("login")
    @ApiResult(MemberEntity)
    @ApiOperation({ summary: '用户登陆接口' })
    async login(@Body() userLoginReqVo: UserLoginReqVo) {
        return await this.memberService.login(userLoginReqVo)
    }

    /**
     * 获取用户信息
     * @returns 
     */
    @Post("getUserInfo")
    @ApiResult(MemberEntity)
    @ApiOperation({ summary: '获取用户信息接口' })
    getUserInfo(@Req() request: Request) {
        return ResultVo.successWithData(GetCurrentUser(request))
    }


    /**
     * 校验支付密码
     * @param userIdVo
     */
    @Post("checkPayPassword")
    @ApiResult()
    @ApiOperation({ summary: '检查用户是否设置了支付密码' })
    async checkPayPassword(@Body() userIdVo: UserIdVo) {
        return await this.memberService.checkPayPassword(userIdVo.userId)
    }


    @Post("setPayPassword")
    @ApiResult()
    @ApiOperation({ summary: '设置支付密码' })
    async setPayPassword(@Body() payPasswordVo: PayPasswordVo) {
        return await this.memberService.setPayPassword(payPasswordVo)
    }
}
